<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/html">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="target-densitydpi=device-dpi, width=device-width, initial-scale=1.0, maximum-scale=1">
    <meta name="description" content="Modern UI CSS">
    <meta name="author" content="Sergey Pimenov">
    <meta name="keywords" content="windows 8, modern style, modern ui, style, modern, css, framework">

    <link href="css/modern.css" rel="stylesheet">

	<script src="http://code.jquery.com/jquery-1.8.2.js"></script>
    <script src="http://code.jquery.com/ui/1.9.1/jquery-ui.js"></script>
    <link rel="stylesheet" href="http://code.jquery.com/ui/1.9.1/themes/base/jquery-ui.css" />

    <title>Search/Book Flight</title>
    
    <script>
	    $(function() 
	    {
	        $( "#datepicker" ).datepicker();
	    });
    </script>
	

</head>


<body class="modern-ui" onload="prettyPrint()">

<%
	String username = request.getParameter("username");
	String homepage = null;
	String path = "/Website/SelectFlightURL";
	
	if (username == null || username.equals("null"))
	{
		homepage = "/Website/index.html";		
	}
	else
	{
		homepage = "/Website/BackButtonURL?username=" + username;
	} 		
%>

    <div class="page secondary">
        <div class="page-header">
            <div class="page-header-content">
                <h1>Search Flight</h1>
                <a href = "/Website/BackButtonURL?username=<%=username %>" class="back-button big page-back"></a>
            </div>
        </div>
		
        <div class="page-region">
            <div class="page-region-content">
							
				<br>
				<br>
                    <div class="row">
                        <div class="span10">
                            <div class="span10" style="background-color: #ccc; height: 600px;">
                                <div class="page snapped bg-color-pink">
                                    <p style="padding: 20px; color:white">Search Filter</p>
									
									<form action = "/Website/SearchFlightURL" method = "get" style = "padding: 20px">
										<div class="input-control text span3 as-block" >
											<p style="color:white">Leaving from: </p> <input type="text"name = "leaving"/>
											<span class="helper"></span>
										</div>
										
										<div class="input-control text span3 as-block">
											<p style="color:white">Arriving At </p> <input type="text"name = "arriving"/>
											<span class="helper"></span>
										</div>
																												    	
								    	<div class="input-control text span3 as-block">
											<p style="color:white">Date </p> <input type="text" id="datepicker" name = "date" />
											<span class="helper"></span>
										</div>
																																																				
										<input type = "hidden" name = "username" value = <%=username %>>
																				
										<br>
										<input type="submit" value="Search"/>
									
									</form>

                                </div>
                                <div class="page fill bg-color-white">
                                <h2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Direct Flight</h2>
                                
                                <form action = <%=path %> method = "get" style = "padding: 20px">  
									<table class="hovered" style="padding: 20px; width: 900px;">
										<thead>
										<c:choose>
		                            		<c:when test="${isEmpty1=='false'}">
											<tr>
												<th class="Left">ID</th>
												<th class="left">Departure Date</th>
												<th class="left">Arrival Date</th>
												<th class="left">Airline</th>
												<th class="left">Leaving From</th>
												<th class="left">Destination</th>
												<th class="left">Base Price</th>
												<th class="left">Seats Left</th>
											</tr>
															
											<tbody>
												<c:forEach items="${flightList}" var="flightInfo">
													<tr>
														<td>
															<label class="radio" onclick="">
                                   								<input type="radio" name="r1" value = "${flightInfo.flightID}"/>
                                   								<span><c:out value="${flightInfo.flightID}" /></span>
                               								</label>
														</td>
														
														<td><c:out value="${flightInfo.departureTime}" /></td>
														<td><c:out value="${flightInfo.arrivalTime}" /></td>
														<td><c:out value="${flightInfo.airline}" /></td>
														<td><c:out value="${flightInfo.departureLocation}" /></td>
														<td><c:out value="${flightInfo.arrivalLocation}" /></td>
														<td><c:out value="${flightInfo.price}" /></td>
														<td><c:out value="${flightInfo.seatsLeft}" /></td>
			
													</tr>
												</c:forEach>														
											</tbody>
											
											</c:when>
											<c:when test="${isEmpty1=='true'}">
												<tr>
													<th class=Left>No Flights in this category.</th>
												</tr>
											</c:when>		
										</c:choose>		
												
										</thead>
										
									</table>
													
									<input type = "hidden" name = "username" value = <%=username %>>
									
									<div align=left>
										<c:if test="${isEmpty1=='false'}">
											<input type="submit" value="Reserve" style="margin-left: 20px"/>
										</c:if>
									</div>
									
								</form>
								
								<br>
								<br>
								<br>
								
								<h2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Connecting Flight</h2>
                                
                                <form action = "/Website/ConnectingFlightURL" method = "get" style = "padding: 20px">  
									<table class="hovered" style="padding: 20px; width: 800px;">
										<thead>
										
										<c:choose>
		                            		<c:when test="${isEmpty2=='false'}">
										
											<tr>
												<th class="Left">ID</th>
												<th class="left">Date</th>
												<th class="left">Airline</th>
												<th class="left">Leaving From</th>
												<th class="left">Destination</th>
												<th class="left">Price</th>
												<th class="left">Seats Left</th>
											</tr>
															
											<tbody>
												<c:forEach items="${connectList}" var="connectInfo">
													<tr>
														<td>
															<label class="radio" onclick="">
                                   								<input type="radio" name="r1" value = "${connectInfo.bothFlightID}"/>
                                   								<span>
                                   									<c:out value="${connectInfo.bothFlightID}" />
                                   								</span>
                               								</label>
														</td>	
														
														<td>
															<c:out value="${connectInfo.date1}" />
															<br>
															<c:out value="${connectInfo.date2}" />
														</td>	
														
														<td>
															<c:out value="${connectInfo.airline1}" />
															<br>
															<c:out value="${connectInfo.airline2}" />
														</td>
														
														<td>
															<c:out value="${connectInfo.departureLocation1}" />
															<br>
															<c:out value="${connectInfo.departureLocation2}" />
														</td>
														
														<td>
															<c:out value="${connectInfo.arrivalLocation1}" />
															<br>
															<c:out value="${connectInfo.arrivalLocation2}" />
														</td>
														
														<td>
															<c:out value="${connectInfo.totalPrice}" />
														</td>
														
														<td>
															<c:out value="${connectInfo.seatsLeft1}" />
															<br>
															<c:out value="${connectInfo.seatsLeft2}" />
														</td>
																
													</tr>
												</c:forEach>															
											</tbody>
											
											</c:when>
											<c:when test="${isEmpty2=='true'}">
												<tr>
													<th class=Left>No connecting flights in this category.</th>
												</tr>
											</c:when>		
										</c:choose>	
															
										</thead>
									</table>
													
									<input type = "hidden" name = "username" value = <%=username %>>
									
									<div align=left>
										<c:if test="${isEmpty2=='false'}">
											<input type="submit" value="Reserve" style="margin-left: 20px"/>
										</c:if>
									</div>
									
								</form>
									
                                </div>
                            </div>
							
							
                        </div>
                    </div>


            </div>
        </div>

    </div>

</body>
</html>